package io.github.chutian0610.sqlparser.dialect

import io.github.chutian0610.sqlparser.token.CodePoint

class MySQL : Dialect {
    /**
     * mysql use
     * @see [character escape sequences](https://dev.mysql.com/doc/refman/8.0/en/string-literals.html#character-escape-sequences)
     */
    override fun supportsStringLiteralBackslashEscape(): Boolean = true

    override fun supportsNumericPrefix(): Boolean = true

    override fun isIdentifierPart(c: CodePoint): Boolean {
        return isIdentifierStart(c)
                || c.isAsciiDigit()
                // MySQL implements Unicode characters in identifiers.
                || !c.isAscii()
    }

    override fun isIdentifierStart(c: CodePoint): Boolean {
        // See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html.
        // Identifiers which begin with a digit are recognized while tokenizing numbers,
        // so they can be distinguished from exponent numeric literals.
        // MySQL also implements non ascii utf-8 charecters
        return c.isAlphabetic()
                || CodePoint.equalsChar(c, '_')
                || CodePoint.equalsChar(c, '$')
                || CodePoint.equalsChar(c, '@')
                || c.inIntRange('\u0080'.code..'\uffff'.code)
                || !c.isAscii()
    }

    override fun isDelimitedIdentifierStart(c: CodePoint): Boolean = CodePoint.equalsChar(c, '`')

    override fun requiresSingleLineCommentWhitespace(): Boolean = true

}